package com.tutu.common.util;

import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;

public class AppUtil implements ApplicationContextAware {

	private static ApplicationContext applicationContext;
	@Override
	public void setApplicationContext(ApplicationContext contex)
			throws BeansException {
		applicationContext = contex;
	}

	public static Map<String, Object> getImplInstance(Class clazz){
		Map<String, Object> map = applicationContext.getBeansOfType(clazz);
		return map;
	}
	
	public static <C> C getBean(Class<C> cls){
		return applicationContext.getBean(cls);
	}
	
	public static Object getBean(String beanId){
		return applicationContext.getBean(beanId);
	}
	
	public static void publishEvent(ApplicationEvent applicationEvent){
		applicationContext.publishEvent(applicationEvent);
	}
}
